-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Remove __SHORT_FILE__ macro definition in CMake #152344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-llvm-support Author: Mehdi Amini (joker-eph) ChangesThis per-file macro definition on the command line breaks caching of modules. See discussion in #150677 Instead we use a constexpr variable to force the constexpr evaluation by the frontend, and also the FILE_NAME macro when available (clang/gcc) to spare compile-time in the frontend. Full diff: https://github.com/llvm/llvm-project/pull/152344.diff 3 Files Affected:
diff --git a/llvm/cmake/modules/LLVMProcessSources.cmake b/llvm/cmake/modules/LLVMProcessSources.cmake
index cf358a88f5fb6..0670d60bf2afd 100644
--- a/llvm/cmake/modules/LLVMProcessSources.cmake
+++ b/llvm/cmake/modules/LLVMProcessSources.cmake
@@ -58,21 +58,6 @@ function(llvm_process_sources OUT_VAR)
set(sources ${ARG_UNPARSED_ARGUMENTS})
llvm_check_source_file_list(${sources})
- # Don't generate __SHORT_FILE__ on VS builds as it can prevent build parallelisation.
- if(NOT CMAKE_GENERATOR MATCHES "Visual Studio")
- foreach(fn ${sources})
- get_filename_component(suf ${fn} EXT)
- if("${suf}" STREQUAL ".cpp" OR "${suf}" STREQUAL ".c")
- get_filename_component(short_name ${fn} NAME)
- set_property(
- SOURCE ${fn}
- APPEND
- PROPERTY COMPILE_DEFINITIONS __SHORT_FILE__="${short_name}")
- endif()
- endforeach()
- endif()
-
-
# This adds .td and .h files to the Visual Studio solution:
add_td_sources(sources)
find_all_header_files(hdrs "${ARG_ADDITIONAL_HEADER_DIRS}")
diff --git a/llvm/include/llvm/Support/DebugLog.h b/llvm/include/llvm/Support/DebugLog.h
index a3312950da94e..e3a0854608565 100644
--- a/llvm/include/llvm/Support/DebugLog.h
+++ b/llvm/include/llvm/Support/DebugLog.h
@@ -56,30 +56,30 @@ namespace llvm {
DEBUGLOG_WITH_STREAM_AND_TYPE(llvm::dbgs(), LEVEL, DEBUG_TYPE)
#define LDBG_LOG_LEVEL_1() LDBG_LOG_LEVEL(1)
+// We want the filename without the full path. We are using the __FILE__ macro
+// and a constexpr function to strip the path prefix. We can avoid the frontend
+// repeated evaluation of __FILE__ by using the __FILE_NAME__ when defined
+// (gcc and clang do) which contains the file name already.
+#if !defined(__FILE_NAME__)
+#define __FILE_NAME__ ::llvm::impl::getShortFileName(__FILE__)
+#endif
+
#define DEBUGLOG_WITH_STREAM_TYPE_FILE_AND_LINE(STREAM, LEVEL, TYPE, FILE, \
LINE) \
for (bool _c = \
(::llvm::DebugFlag && ::llvm::isCurrentDebugType(TYPE, LEVEL)); \
_c; _c = false) \
- for (::llvm::impl::RAIINewLineStream NewLineStream{(STREAM)}; _c; \
- _c = false) \
+ for (constexpr auto file = __FILE_NAME__; _c; _c = false) \
+ for (::llvm::impl::RAIINewLineStream NewLineStream{(STREAM)}; _c; \
+ _c = false) \
::llvm::impl::raw_ldbg_ostream{ \
::llvm::impl::computePrefix(TYPE, FILE, LINE, LEVEL), NewLineStream} \
.asLvalue()
#define DEBUGLOG_WITH_STREAM_TYPE_AND_FILE(STREAM, LEVEL, TYPE, FILE) \
DEBUGLOG_WITH_STREAM_TYPE_FILE_AND_LINE(STREAM, LEVEL, TYPE, FILE, __LINE__)
-// When __SHORT_FILE__ is not defined, the File is the full path,
-// otherwise __SHORT_FILE__ is defined in CMake to provide the file name
-// without the path prefix.
-#if defined(__SHORT_FILE__)
#define DEBUGLOG_WITH_STREAM_AND_TYPE(STREAM, LEVEL, TYPE) \
- DEBUGLOG_WITH_STREAM_TYPE_AND_FILE(STREAM, LEVEL, TYPE, __SHORT_FILE__)
-#else
-#define DEBUGLOG_WITH_STREAM_AND_TYPE(STREAM, LEVEL, TYPE) \
- DEBUGLOG_WITH_STREAM_TYPE_AND_FILE(STREAM, LEVEL, TYPE, \
- ::llvm::impl::getShortFileName(__FILE__))
-#endif
+ DEBUGLOG_WITH_STREAM_TYPE_AND_FILE(STREAM, LEVEL, TYPE, __FILE__)
namespace impl {
diff --git a/llvm/unittests/Support/DebugLogTest.cpp b/llvm/unittests/Support/DebugLogTest.cpp
index c24d1a5693169..05a49163552a5 100644
--- a/llvm/unittests/Support/DebugLogTest.cpp
+++ b/llvm/unittests/Support/DebugLogTest.cpp
@@ -7,9 +7,9 @@
//===----------------------------------------------------------------------===//
// This macro is defined in the LLVM build system, but we undefine it here
-// so that we test at least once in-tree the case where __SHORT_FILE__ is not
+// so that we test at least once in-tree the case where __FILE_NAME__ is not
// defined.
-#undef __SHORT_FILE__
+#undef __FILE_NAME__
#include "llvm/Support/DebugLog.h"
#include "llvm/ADT/Sequence.h"
|
This per-file macro definition on the command line breaks caching of modules. See discussion in llvm#150677 Instead we use a constexpr variable to force the constexpr evaluation by the frontend, and also the __FILE_NAME__ macro when available (clang/gcc) to spare compile-time in the frontend.
91d16a0
to
3918596
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/42/builds/5689 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/136/builds/4873 Here is the relevant piece of the build log for the reference
|
This per-file macro definition on the command line breaks caching of modules. See discussion in #150677
Instead we use a constexpr variable to force the constexpr evaluation by the frontend, and also the FILE_NAME macro when available (clang/gcc) to spare compile-time in the frontend.